#!/bin/bash

if [ $EUID -ne 0 ]; then
   echo "Must have superuser permissions"
   exit 1
fi

# Clean build directory
find . -name "Makefile" -delete
find . -name "*.o" -delete
find . -name "*.cpp" -delete

# Create install directories
DIR_ROOT=/led
DIR_OPER=$DIR_ROOT/operational
DIR_CMDS=$DIR_OPER/commands
DIR_DATA=$DIR_OPER/data
DIR_EVENTS=$DIR_OPER/events

mkdir -v -p -m 755 $DIR_ROOT
mkdir -v -p -m 755 $DIR_OPER
mkdir -v -p -m 755 $DIR_CMDS
mkdir -v -p -m 755 $DIR_DATA
mkdir -v -p -m 755 $DIR_EVENTS

# Copy binaries
cp core -r $DIR_ROOT
cp plugins -r $DIR_ROOT
cp startup.sh $DIR_ROOT/core

# Copy config
cp config -r $DIR_OPER

# Change permissions
chmod -R 755 $DIR_ROOT

